package com.rizzo.back.domain;

import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/**
 * TODO Insert JavaDoc!
 */
@Entity
@Table(name = "rizzo.rizzo_blog_entry")
@Indexed
public class BlogEntry {

    private Long id;

    private BlogUser blogUser;

    private String title;

    private String content;

    private Set<Tag> tags;

    private Date createDate;

    private boolean published;

    /**
     * Method getId returns the id of this BlogEntry object.
     *
     * @return the id (type Long) of this BlogEntry object.
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @DocumentId
    @Column(name = "id", nullable = false)
    public Long getId() {
        return id;
    }

    /**
     * Method setId sets the id of this BlogEntry object
     *
     * @param id of type Long
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Method getBlogUser returns the blogUser of this BlogEntry object.
     *
     * @return the blogUser (type BlogUser) of this BlogEntry object.
     */
    @OneToOne(cascade = CascadeType.REFRESH)
    @JoinColumn(name = "blog_user_id", nullable = false)
    public BlogUser getBlogUser() {
        return blogUser;
    }

    /**
     * Method setBlogUser sets the blogUser of this BlogEntry object
     *
     * @param blogUser of type BlogUser
     */
    public void setBlogUser(BlogUser blogUser) {
        this.blogUser = blogUser;
    }

    /**
     * Method getTitle returns the title of this BlogEntry object.
     *
     * @return the title (type String) of this BlogEntry object.
     */
    @Field
    @Column(name = "title", nullable = false)
    public String getTitle() {
        return title;
    }

    /**
     * Method setTitle sets the title of this BlogEntry object
     *
     * @param title of type String
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * Method getContent returns the content of this BlogEntry object.
     *
     * @return the content (type String) of this BlogEntry object.
     */
    @Field
    @Column(name = "content", nullable = false)
    public String getContent() {
        return content;
    }

    /**
     * Method setContent sets the content of this BlogEntry object
     *
     * @param content of type String
     */
    public void setContent(String content) {
        this.content = content;
    }

    /**
     * Method getTags returns the tags of this BlogEntry object.
     *
     * @return the tags (type Set<Tag>) of this BlogEntry object.
     */
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "blogEntry", fetch = FetchType.EAGER)
    public Set<Tag> getTags() {
        return tags;
    }

    /**
     * Method setTags sets the tags of this BlogEntry object
     *
     * @param tags of type Set<Tag>
     */
    public void setTags(Set<Tag> tags) {
        this.tags = tags;
    }

    /**
     * Method getCreateDate returns the createDate of this BlogEntry object.
     *
     * @return the createDate (type Date) of this BlogEntry object.
     */
    @Column(name = "create_date", nullable = false)
    public Date getCreateDate() {
        return createDate;
    }

    /**
     * Method setCreateDate sets the createDate of this BlogEntry object
     *
     * @param createDate of type Date
     */
    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    /**
     * Method isPublished returns the published of this BlogEntry object.
     *
     * @return the published (type boolean) of this BlogEntry object.
     */
    @Column(name = "published", nullable = false)
    public boolean isPublished() {
        return published;
    }

    /**
     * Method setPublished sets the published of this BlogEntry object
     *
     * @param published of type boolean
     */
    public void setPublished(boolean published) {
        this.published = published;
    }
}
